package org.dbrd.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReportBuckets {

	/**
	 * key: master report id;<br>
	 * value: a set of all its duplicates and itself.
	 */
	private Map<Integer, MasterDetectionBugReport> index = new HashMap<Integer, MasterDetectionBugReport>();

	/**
	 * to reserve the order
	 */
	private List<MasterDetectionBugReport> masters = new ArrayList<MasterDetectionBugReport>();

	public void addReport(DetectionBugReport report) {
		if (report instanceof MasterDetectionBugReport) {
			this.index.put(report.getId(), (MasterDetectionBugReport) report);
			this.masters.add((MasterDetectionBugReport) report);
		} else if (report instanceof DuplicateDetectionBugReport) {
			this.index.get(report.getDuplicateId()).addDuplicate((DuplicateDetectionBugReport) report);
		}
	}

	/**
	 * you really should not modify this list although i return a modifiable one
	 * to you. This is not me. I am just considering the performance.
	 * 
	 * @return
	 */
	public List<MasterDetectionBugReport> getBuckets() {
		return this.masters;
	}
	
	public MasterDetectionBugReport getMasterReport(int id) {
		return this.index.get(id);
	}

}